package com.xsoft.demo11;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

public class MainActivity extends AppCompatActivity {
    private Button linearLayout;
    private Button gridLayout;
    private Button staggeredGridLayout;
    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        linearLayout = (Button) findViewById(R.id.linear_layout);
        linearLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initLinearAdapter();
            }
        });
        gridLayout = (Button) findViewById(R.id.grid_layout);
        gridLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initGridAdapter();
            }
        });
        staggeredGridLayout = (Button) findViewById(R.id.staggered_grid_layout);
        staggeredGridLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                initStaggeredGridAdapter();
            }
        });
        recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        initLinearAdapter();
    }

    private void initLinearAdapter() {
        recyclerView.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL, false));
        MyRecyclerAdapter adapter = new MyRecyclerAdapter(R.layout.view_item_shop_list);
        recyclerView.setAdapter(adapter);
        adapter.bindData(initData());
    }

    private void initGridAdapter() {
        recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        MyRecyclerAdapter adapter = new MyRecyclerAdapter(R.layout.view_item_shop_grid);
        recyclerView.setAdapter(adapter);
        adapter.bindData(initData());
    }

    private void initStaggeredGridAdapter() {
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        MyRecyclerAdapter adapter = new MyRecyclerAdapter(R.layout.view_item_shop_grid);
        recyclerView.setAdapter(adapter);
        adapter.bindData(initData());
    }


    private List<GoodsInfo> initData() {
        List<GoodsInfo> infos = new ArrayList<>();
        GoodsInfo info1 = new GoodsInfo();
        info1.setName("玉兰油护肤套装");
        info1.setDetail("Olay玉兰油 水感透白光塑钻纹弹力面膜");
        info1.setPrice(128.00f);
        info1.setPictureAlbum("olay.jpg");
        info1.setPicture("olay.jpg");
        infos.add(info1);
        GoodsInfo info2 = new GoodsInfo();
        info2.setName("肌肤之食");
        info2.setDetail("肌肤之食 氨基酸洗面奶女男士泡沫洁面乳 敏感肌可用补水保湿清爽控油去黑头 去角质收缩毛孔深层清洁 氨基酸洗面奶230ml");
        info2.setPrice(69.90f);
        info2.setPictureAlbum("elate.jpg");
        info2.setPicture("elate.jpg");
        infos.add(info2);
        GoodsInfo info3 = new GoodsInfo();
        info3.setName("马丁护肤三件套");
        info3.setDetail("马丁男士古龙香氛洗面奶面霜保湿水面部护肤三件套（爽肤水120ml+焕肤乳50ml+洁面乳150ml）");
        info3.setPrice(199.00f);
        info3.setPictureAlbum("martin.jpg");
        info3.setPicture("martin.jpg");
        infos.add(info3);
        GoodsInfo info4 = new GoodsInfo();
        info4.setName("罗兰");
        info4.setDetail("罗兰（LUOLAN）罗兰香皂手工皂玫瑰精油皂128克清洁毛孔清爽控油洁面洗脸沐浴澡女香肥皂10盒 10盒玫瑰");
        info4.setPrice(93.80f);
        info4.setPictureAlbum("luolan.jpg");
        info4.setPicture("luolan.jpg");
        infos.add(info4);
        GoodsInfo info5 = new GoodsInfo();
        info5.setName("悦诗风吟洁面");
        info5.setDetail("悦诗风吟 Innisfree 绿茶精萃保湿洗面奶洁面乳洁面膏 150mlx2只装（洗面奶男女 清爽不绷紧）");
        info5.setPrice(60.00f);
        info5.setPictureAlbum("innisfree.jpg");
        info5.setPicture("innisfree.jpg");
        infos.add(info5);
        GoodsInfo info6 = new GoodsInfo();
        info6.setName("欧莱雅洁面乳");
        info6.setDetail("欧莱雅（LOREAL）清润葡萄籽水嫩净透光采氨基酸洁面乳125ml(洗面奶女 改善暗沉清洁肌肤 补水保湿 男女通用)");
        info6.setPrice(110.00f);
        info6.setPictureAlbum("loreal.jpg");
        info6.setPicture("loreal.jpg");
        infos.add(info6);
        GoodsInfo info7 = new GoodsInfo();
        info7.setName("珂润洁面泡沫");
        info7.setDetail("日本珂润（Curel）润浸保湿洁颜泡沫 150ml（泡泡慕斯洁面乳温和敏感肌适用深层清洁男女士花王进口）");
        info7.setPrice(108.00f);
        info7.setPictureAlbum("curel.jpg");
        info7.setPicture("curel.jpg");
        infos.add(info7);
        GoodsInfo info8 = new GoodsInfo();
        info8.setName("珀莱雅洁面乳");
        info8.setDetail("珀莱雅去角质啫喱面部身体去死皮膏男女去黑头洗面奶磨砂膏慕斯学生");
        info8.setPrice(35.00f);
        info8.setPictureAlbum("proya.jpg");
        info8.setPicture("proya.jpg");
        infos.add(info8);
        return infos;
    }
}